<template>
  <view>
    <view class="album_bg">
      <image mode="widthFix" :src="album.cover"></image>
      <view class="info">
        <view class="name">{{album.name}}</view>
        <view class="btn">关注专辑</view>
      </view>
    </view>
    <view class="album_author">
      <view class="info">
        <image mode="widthFix" :src="album.user.avatar"></image>
        <view class="name">{{album.user.name}}</view>
      </view>
      <view class="desc">
        <text>{{album.desc}}</text>
      </view>
    </view>
    <view class="album_list">
      <view class="item" v-for="(item,index) in wallpaper" :key="item.id">
        <go-detail :list="wallpaper" :index="index">
          <image mode="aspectFill" :src="item.thumb+item.rule.replace('$<Height>',360)"></image>
        </go-detail>
      </view>
    </view>
  </view>
</template>

<script>
import goDetail from '@/components/goDetail'
  export default {
    data() {
      return {
        params:{
          limit:30,
          order:"new",
          skip:0,
          first:1
        },
        id:-1,
        album:{},
        wallpaper:[],
        hasMore:true
      }
    },
    components:{
      goDetail
    },
    onLoad(options){
      //console.log(options.id)
      this.id=options.id
      //this.id='5dea515de7bce73981faf1a9'
      //this.id='5e206ca6e7bce73981fb0752'
      this.getList()
    },
    //上拉加载
    onReachBottom(){
      if (this.hasMore) {
        this.params.first=0
        this.params.skip+=this.params.limit
        this.getList()  
      } else {
        uni.showToast({
          title:"没有数据了",
          icon:"none"
        })
      }
    },
    methods: {
      getList(){
        this.request({
          url:`http://157.122.54.189:9088/image/v1/wallpaper/album/${this.id}/wallpaper`,
          data:this.params
        }).then(res=>{
          //console.log(res)
          if (Object.keys(this.album).length===0) {
            this.album=res.res.album
          }
          if (res.res.wallpaper.length===0) {
            this.hasMore=false
            uni.showToast({
              title:"没有数据了",
              icon:"none"
            })
            return
          }
          this.wallpaper=[...this.wallpaper,...res.res.wallpaper]
        })
      }
    },
  }
</script>

<style lang="scss" scoped>
.album_bg{
  position: relative;
  .info{
    position: absolute;
    width: 100%;
    left: 0;
    bottom: 0;
    display: flex;
    justify-content: space-between;
    height: 80rpx;
    align-items: center;
    color: #fff;
    padding: 0 15rpx;
    .name{
      font-size: 40rpx;
    }
    .btn{
      background-color: $color;
      width: 152rpx;
      height: 60rpx;
      display: flex;
      justify-content: center;
      align-items: center;
      border-radius: 10rpx;
    }
  }
}
.album_author{
  padding: 10rpx;
  .info{
    padding: 10rpx 0;
    display: flex;
    image{
      width: 50rpx;
    }
    .name{
      color: #000;
      margin-left: 15rpx;
    }
  }
  .desc{}
}
.album_list{
  display: flex;
  flex-wrap: wrap;
  .item{
    width: 33.33%;
    padding: 5rpx;
    image{
      height: 160rpx;
    }
  }
}
</style>